1927E - Klever Permutation - CodeForces Solution


constructive algorithms math

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

#define vc vector<char>
#define vll vector <long long>
#define vi vector <int>
#define vld vector<long double>
#define vpi vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>

#define all(v) v.begin(),v.end()
#define repl(i,a,b) for(long long i=a;i<b;i++)
#define repi(i,a,b) for(int i=a;i<b;i++)
#define nl cout<<endl
#define e endl
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define lb(a,x) lower_bound(a.begin(),a.end(),x)
#define ub(a,x) upper_bound(a.begin(),a.end(),x)
#define f first
#define sc second
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define in(v) for(int i=0;i<v.size();i++) cin>>v[i];
#define debug(x) cout<<#x<<" "<<x<<endl;

int lo(char s){
    if(s>='a' && s<='z') return 1;
    else if(s>='A' && s<='Z')   return 2;
    else return 0;
}

void vp() {

    int n,k; cin >> n >> k ;
    int n2 = n ;
    vll v(n,-1) ;
    // int c = 0 ;
    
    repi( j , 0 , k/2 ) {
        
        for(int i = 2*j ; i < n ; i += k ) {
            v[i] = n2 ;
            n2-- ;
        }
    }

    n2=1;

    for(int j=k/2-1 ; j>=0 ; j-- ){
        for(int i = 2*j+1 ; i<n;i+=k ){
            v[i] = n2;
            n2++;
        }
    }
//2 1 0 -> 5 3 1
    for(auto i:v) cout<<i<<" "; nl;

}


int main()
{   
    IOS;
    ll t=1;
    cin >> t;
    while (t--)
        vp();

    return 0;
}


Comments

Submit
0 Comments
More Questions

1703A - YES or YES
494A - Treasure
48B - Land Lot
835A - Key races
1622C - Set or Decrease
1682A - Palindromic Indices
903C - Boxes Packing
887A - Div 64
755B - PolandBall and Game
808B - Average Sleep Time
1515E - Phoenix and Computers
1552B - Running for Gold
994A - Fingerprints
1221C - Perfect Team
1709C - Recover an RBS
378A - Playing with Dice
248B - Chilly Willy
1709B - Also Try Minecraft
1418A - Buying Torches
131C - The World is a Theatre
1696A - NIT orz
1178D - Prime Graph
1711D - Rain
534A - Exam
1472A - Cards for Friends
315A - Sereja and Bottles
1697C - awoo's Favorite Problem
165A - Supercentral Point
1493A - Anti-knapsack
1493B - Planet Lapituletti